<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        header {
            width: 100%;
            height: 1.333333rem;
            background-color: orange;
        }
        
        header img {
            position: absolute;
            left: 8.666667rem;
            width: .906667rem;
            height: .906667rem;
            top: .2rem;
        }
        
        header span {
            color: #fff;
            font-size: .56rem;
        }
        
        header span:nth-child(2) {
            margin-left: 2.4rem;
        }
        
        #weixin2 {
            width: 9.493333rem;
            height: 4.026667rem;
        }
    </style>
</head>
<script src="../js/flexible.js"></script>

<body>
    <header id="header">
        <span>&lt</span>
        <span>省钱控-最新优惠</span>
        <img src="./../assets/images/header_app.png" alt="">
    </header>
    <div id="content"></div>

    <script>
        //获取浏览器地址中的query参数

        function getUrlParams() {
            let url = location.href;
            let regExp = /.*\?([^\?]+)/
            let query = {}; //最终处理好的参数
            let search = regExp.exec(url);
            //productid=23&NAME=123"
            // console.log(search);
            search = search[1];
            //有没有多个query参数,有的话肯定以&进行连接
            let searchArr = [];
            if (search.indexOf("&")) {
                searchArr = search.split("&")
            } else {
                search = search.split()
            }

            searchArr.forEach(item => {
                let queryArr = item.split("=");
                query[queryArr[0]] = queryArr[1]
            })

            return query
        }

        let query = getUrlParams();

        console.log(query);


        fetch("http://chst.vip:1234/api/getmoneyctrlproduct?productid=" + query.productid)
            .then(body => body.json())
            .then(res => {
                res = res.result;
                let html = "";
                res.forEach(item => {
                    html += `
                    <h1>${item.productName}</h1>
                    <span>${item.productFrom}</span><br><span>${item.productTime}</span><span>${item.productTips}</span>
                    <h1>${item.productImgSm}</h1>
                    
                    <h2>${item.productInfo}</h2>
                    <h1>${item.productImgLg}</h1>
                    ${item.productCity}

                    <img src="./../assets/images/mmbweixin2.png" id="weixin2">

                    ${item.productComment}
                    `
                })

                content.innerHTML = html
            })
    </script>
</body>

</html>